var lib={};
(function(){
	function touchEvnet(config){
		var obj=config.elem;
		var This=this;
		var touch={};
		//0x01 上下   0x10 左右
		function move(e){
			if(e.targetTouches.length>1)return ;
			touch.moveX=parseInt(e.targetTouches[0].pageX);
			touch.moveY=parseInt(e.targetTouches[0].pageY);
			var x=touch.moveX-touch.startX;
			var y=touch.moveY-touch.startY;
			touch.status=Math.abs(x)==Math.abs(y)?null:(Math.abs(x)>Math.abs(y)?true:false);
			if(touch.status==false&&parseInt(config.status)&0x01)
			{
				e.preventDefault();
			}else if(touch.status&&parseInt(config.status)&0x10){
				e.preventDefault();
			}
			
		}
		function end(e){
			var msg='';
			var x=touch.moveX-touch.startX;
			var y=touch.moveY-touch.startY;
			touch.status=Math.abs(x)>Math.abs(y)+30?true:false;
			if(touch.status===true)
			{
				msg=touch.moveX>touch.startX?'e':'w';
			}else if(touch.status===false){
				msg=touch.moveY>touch.startY?'s':'n';
			}
			if(typeof config.touchStatus==='function')
			{
				config.touchStatus(msg);
			}
			
		}
		function start(e){
			//console.log(end);
			touch.startX=parseInt(e.targetTouches[0].pageX);
			touch.startY=parseInt(e.targetTouches[0].pageY);
			obj.addEventListener('touchmove',move,false);
			obj.addEventListener('touchend',end,false);
		}
		obj.addEventListener('touchstart',start,false);
	}
	
	
	
	
	lib.touch=touchEvnet;
})();
export default lib;